package pws::ex1;
use strict;
use SSWebServer;

# demo: basic web method
# url: /pws/ex1/getuser?id=1 or /getuser?id=1 (because pws::ex1 is set the default module in conf.pl), or /dir1/app500/getuser.jsp?id=1 (vpath mapping is set in conf.pl)
sub getuser : method
{
	my $id = param("id");
	unless (defined $id) {
		setContent('[1, "param error: id"]');
		return;
	}
	setContentFile("./web/ex1/user$id.json");
}

# demo: default method
# url: /pws/ex1/default?id=1 or /pws/ex1/?id=1 (or /?id=1 but only available if def_page does not exists)
sub default : method
{
	getuser(@_);
}

# demo: param array; usePrint
# url: /pws/ex1/getusers?id=1&id=2
sub getusers : method
{
	usePrint();
	my $idList = param('@id');
	print "[\n";
	my $cnt = 0;
	for my $id (@$idList) {
		print "," if $cnt++ != 0;
		print readFile("./web/ex1/user$id.json");
	}
	print "]\n";
}
1;
